package cn.tedu.boot61.controller;

import cn.tedu.boot61.mapper.CommentMapper;
import cn.tedu.boot61.vo.Comment;
import cn.tedu.boot61.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@RestController
public class CommentController {
    @Autowired(required = false)
    CommentMapper mapper;

    @RequestMapping("/comment/insert")
    public int insert(HttpSession session, Comment comment){
        User u = (User) session.getAttribute("u");
        if (u == null){
            return 2;//没有登录请先登录
        }
        comment.setAuthor(u.getNick());
        comment.setCreated(new Date());
        mapper.insert(comment);
        return 1;
    }

    @RequestMapping("/comment/select")
    public List<Comment> select(int id){
        return mapper.selectByWeiboId(id);
    }

}
